/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package example.hello;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author doo
 */
@WebServlet(name = "cleanDB", urlPatterns = {"/cleanDB"})
public class cleanDB extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method. Méthode GET de la servlet. Elle ne consiste qu'à
     * rediriger vers la page principale, pour le moment.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);

        // Redirection vers le formulaire index.jsp
        getServletContext().getRequestDispatcher("/index.jsp")
                .forward(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method. Méthode POST de la servlet, utilisé lorsqu'on
     * appuie sur le bouton de validation du formulaire.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        processRequest(request, response);
        
//        Monitoring m = (Monitoring) Naming.lookup("//localhost/Monitoring");
//        SystemInfo display = m.quid();
//        System.out.println("ip du serveur : " + display.getIp().getIp());
        InterfaceSQL requete = new InterfaceSQL();
        String truncate = "truncate monito.grossetable;";
        try {
            requete.sendReq(InterfaceSQL.TypeReq.truncate, truncate);
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println(" <head>");
            out.println("retour à l'accueil");
            out.println("<a href=\"index.jsp\">Retour</a>");
            out.println("</html>");
            out.println(" </head>");
        } catch (SQLException ex) {
            Logger.getLogger(List.class.getName()).log(Level.SEVERE, null, ex);
        }
        requete.closeAll();
    }
}
